var app = getApp();

Page({
  onLoad: function(options) {
    var isLogin = wx.getStorageSync('isLogin');
    if (!isLogin) {
      wx.redirectTo({
        url: "../welcome/welcome"
      })
    } else {
      this.wxLogin();
    }
  },
  onAppointmentTap: function() {
    wx.navigateTo({
      url: "../appointment/appointment"
    })
  },
  onQueryTap: function() {
    wx.navigateTo({
      url: "../query/query"
    })
  },
  wxLogin: function() {
    wx.login({
      success(res) {
        if (res.code) {
          wx.request({
            url: app.globalData.apiBaseUrl + '/wechat/index',
            data: {
              code: res.code
            },
            success: function(res) {
              wx.setStorageSync('openid', res.data.openid);
            }
          })
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  }
})